<?php

class YamiiController extends Controller
{
	public function actionAbout()
	{
		if (strtolower(Yii::app()->language) == 'en_gb')
			$this->render('about');
		else {
			Yii::app()->language = 'fi_fi';
			$this->render('about_fi');
		}
	}

	public function actionFaq()
	{
		if (strtolower(Yii::app()->language) == 'en_gb')
			$this->render('faq');
		else {
			Yii::app()->language = 'fi_fi';
			$this->render('faq_fi');
		}
	}

	public function actionPrivacy()
	{
		$this->render('privacy');
	}

	public function actionTerms()
	{
		$this->render('terms');
	}

	public function actionJobs()
	{
		$this->render('jobs');
	}
	
	/**
	 * yamii/feedback
	 */
	public function actionFeedback()
	{
		$submited = Yii::app()->request->getParam('submit');
		if (empty($submited)) {
			if (Yii::app()->request->isAjaxRequest)
				$this->renderPartial('feedback');
			else $this->render('feedback');
		} else {
			//submit feeback (email + content)
			if (Yii::app()->user->isGuest) {
				$email = Yii::app()->request->getPost('email');
				$email_val = filter_var($email, FILTER_VALIDATE_EMAIL);
				if ($email_val === false) {
					BUtils::Logging('feedback_invalid_email', array(
						'POST' => $_POST,
						'ip' => Yii::app()->request->getUserHostAddress(),
					));
					BUtils::sendJSON(500, BUtils::T('email_address_error_msg'));
				} else {
					$email = $email_val;
				}
			} else {
				$email = Yii::app()->user->getState('email');
			}
			if (empty($email)) {
				BUtils::sendJSON(500, BUtils::T('email_address_error_msg'));
			}
			
			$content = Yii::app()->request->getPost('content', null);
			if (empty($content)) {
				BUtils::sendJSON(500, 'Please input content.');
			}
			
			try {
				BUtils::sendMaiToAdmin('Yamii User Feedback - ' . date('Y-m-d'), $content, $email);
			} catch (Exception $ex) {
				BUtils::sendJSON(500, 'Send failed.' . $ex->getMessage());
			}
		}
	}
}